Conditions | 19 |
Total Lines | 54 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like helper.ts ➔ sortRankings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | export function mapMatchStatus(statusCode) { |
||
176 | |||
177 | export function sortRankings(a: RankingDataTeamObject, b: RankingDataTeamObject) { |
||
178 | // Rank lager: A stijgt in sortering. |
||
179 | if (a.rank < b.rank) { |
||
180 | return -1 |
||
181 | } |
||
182 | if (a.rank > b.rank) { |
||
183 | return 1 |
||
184 | } |
||
185 | // Aantal overwinningen hoger: A stijgt in sortering. |
||
186 | if (a.wins > b.wins) { |
||
187 | return -1 |
||
188 | } |
||
189 | if (a.wins < b.wins) { |
||
190 | return 1 |
||
191 | } |
||
192 | // Doelpuntensaldo beter: A stijgt in sortering. |
||
193 | if (a.goalsScored - a.goalsConceded > b.goalsScored - b.goalsConceded) { |
||
194 | return -1 |
||
195 | } |
||
196 | if (a.goalsScored - a.goalsConceded < b.goalsScored - b.goalsConceded) { |
||
197 | return 1 |
||
198 | } |
||
199 | // Aantal gemaakte doelpunten hoger: A stijgt in sortering. |
||
200 | if (a.goalsScored > b.goalsScored) { |
||
201 | return -1 |
||
202 | } |
||
203 | if (a.goalsScored < b.goalsScored) { |
||
204 | return 1 |
||
205 | } |
||
206 | // Aantal uitoverwinningen hoger: A stijgt in sortering. |
||
207 | if (a.winsAway > b.winsAway) { |
||
208 | return -1 |
||
209 | } |
||
210 | if (a.winsAway < b.winsAway) { |
||
211 | return 1 |
||
212 | } |
||
213 | // Doelpuntensaldo op verplaatsing beter: A stijgt in sortering. |
||
214 | if (a.goalsScoredAway - a.goalsConcededAway > b.goalsScoredAway - b.goalsConcededAway) { |
||
215 | return -1 |
||
216 | } |
||
217 | if (a.goalsScoredAway - a.goalsConcededAway < b.goalsScoredAway - b.goalsConcededAway) { |
||
218 | return 1 |
||
219 | } |
||
220 | // Aantal gemaakte doelpunten op verplaatsing hoger: A stijgt in sortering. |
||
221 | if (a.goalsScoredAway > b.goalsScoredAway) { |
||
222 | return -1 |
||
223 | } |
||
224 | if (a.goalsScoredAway < b.goalsScoredAway) { |
||
225 | return 1 |
||
226 | } |
||
227 | |||
228 | return a.team?.club?.localName.localeCompare(b.team?.club?.localName) |
||
229 | } |
||
230 | |||
248 |